﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.ComponentModel;

namespace Golem.Indexer.Data
{
    public enum FileType {
        [Description("Video")]
        Video,
        [Description("HD Video")]
        HDVideo,
        [Description("Hudba")]
        Audio,
        [Description("Obrázky")]
        Photo,
        [Description("CD obrazy")]
        ISO,
        [Description("Dokumenty")]
        Documents,
        [Description("Playlisty")]
        Playlist,
        [Description("Titulky")]
        Subtitles,
        [Description("Archivy")]
        Archive,
        [Description("Ostatní")]
        Unknown
    }

    public class FileDescriptor
    {
        private string fullname;
        private string name;
        private long size;
        private FileType type;

        public long? MachineId { get; set; }

        public FileDescriptor(String name, String fullname, long size, FileType type, long? machineId = null)
        {
            this.fullname = fullname;
            this.name = name;
            this.size = size;
            this.type = type;
            this.MachineId = machineId;
        }

        public static FileType GetTypeOfFile(String extension)
        {
            if (extension.StartsWith("."))
                extension = extension.Substring(1);

            switch (extension.ToLower())
            {
                case "ogm":
                case "avi":
                case "wmv":
                case "vob":
                case "mpg":
                case "bik":
                    return FileType.Video;

                case "mkv":
                case "mp4":
                case "m4v":
                    return FileType.HDVideo;

                case "mp3":
                case "m4a":
                case "wav":
                case "wma":
                case "flac":
                    return FileType.Audio;

                case "jpg":
                case "jpeg":
                case "png":
                case "bmp":
                case "gif":
                case "dds":
                case "tga":
                case "pdn":
                case "tif":
                case "tiff":
                case "pcx":
                case "tgx":
                    return FileType.Photo;

                case "rtf":
                case "txt":
                case "doc":
                case "docx":
                case "odt":
                case "pdf":
                case "xls":
                case "xlsx":
                case "ppt":
                case "pptx":
                case "html":
                case "htm":
                    return FileType.Documents;

                case "sub":
                case "srt":
                    return FileType.Subtitles;

                case "iso":
                case "bin":
                case "mdf":
                case "nrg":
                    return FileType.ISO;

                case "m3u":
                case "vlc":
                    return FileType.Playlist;

                case "zip":
                case "rar":
                    return FileType.Archive;

                default: return FileType.Unknown;
            }
        }

        public String FullName
        {
            get { return this.fullname; }
            private set { this.fullname = value; }
        }

        public string Name
        {
            get { return this.name; }
            private set { this.name = value; }
        }

        public long Size
        {
            get { return this.size; }
            private set { this.size = value; }
        }

        public FileType Type
        {
            get { return this.type; }
            private set { this.type = value; } 
        }

        public bool IsPlayable
        {
            get
            {
                switch (this.Type)
                {
                    case FileType.Audio:
                    case FileType.HDVideo:
                    case FileType.Playlist:
                    case FileType.Video:
                        return true;
                    default: return false;
                }
            }
        }

        public override string ToString()
        {
            return String.Format("{0} - {1} - {2}", Name, Size, Enum.GetName(typeof(FileType), Type));
        }
    }
}
